package com.shadow.domain;

import javax.persistence.*;
import java.sql.Blob;

/**
 * Created by qq65827 on 2015/1/26.
 */
@Entity
@Table(name="issue_snapshot")
public class IssueSnapshot extends BaseObject {

    @Transient
    public boolean isShot(IssueResource resource) {
        this.setIssue(resource.getIssue());
        this.setContent(resource.getContent());
        this.setDownloads(resource.getDownloads());
        this.setDelete(resource.isDelete());
        this.setName(resource.getName());
        this.setPath(resource.getPath());
        this.setText(resource.getText());
        this.setType(resource.getType());
        this.setSize(resource.getSize());
        return true;
    }




    @ManyToOne
    @JoinColumn(name = "f_issue_id")
    private Issue issue;

    @Enumerated(EnumType.ORDINAL)
    @Column(name = "f_type")
    private IssueResource.ResourceType type;

    @Column(name = "f_name")
    private String name;

    @Column(name = "f_text")
    private String text;

    @Column(name = "f_size")
    private Long size;

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    @Column(name = "f_path")
    private String path;

    @Column(name = "f_content")
    private Blob content;


    @ManyToOne
    @JoinColumn(name = "f_version_id")
    private IssueVersion issueVersion;

    @Column(name = "f_downloads")
    private Integer downloads;


    public IssueVersion getIssueVersion() {
        return issueVersion;
    }

    public void setIssueVersion(IssueVersion issueVersion) {
        this.issueVersion = issueVersion;
    }
    public IssueResource.ResourceType getType() {
        return type;
    }

    public void setType(IssueResource.ResourceType type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Blob getContent() {
        return content;
    }

    public void setContent(Blob content) {
        this.content = content;
    }

    public Integer getDownloads() {
        return downloads;
    }

    public void setDownloads(Integer downloads) {
        this.downloads = downloads;
    }

    public Issue getIssue() {
        return issue;
    }

    public void setIssue(Issue issue) {
        this.issue = issue;
    }




    public IssueSnapshot() {

    }

    public IssueSnapshot(IssueResource.ResourceType type, Blob content) {
        this.type = type;
        this.content = content;
    }



}